package com.yuer;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class Test {

    public static void main(String[] args) {

        try {
            URL url = new URL("https://bookcover.yuewen.com/qdbimg/349573/1010734492/180");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.19 Safari/537.36");
            connection.setConnectTimeout(5 * 1000);
            InputStream inputStream = connection.getInputStream();
            byte[] tmp = new byte[1024];
            int length;
            OutputStream outputStream = new FileOutputStream("/Users/if/Desktop/网站全部资料/qidian-image/image/xxx.jpeg");
            while ((length = inputStream.read(tmp)) != -1) {
                outputStream.write(tmp, 0, length);
            }
            outputStream.close();
            inputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
